<form name="test" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="referMethod" value="article" />
<input type="file" name="imgFile" />
<input type="submit" value="确定" />
</form>

<?php
// 配置Application路径
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../../application'));



// 配置include环境
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));



// 载入配置文件
include 'Zend/Config/Ini.php';
$config = new Zend_Config_Ini(APPLICATION_PATH .'/./configs/application.ini', 'production');


/**
  * 设置图片存放规则
  * path + month + time-uniqid().jpg
  */
include 'Zend/Date.php';
$date = new Zend_Date();
$subPath = $date->toString('YMMdd');
$imageName = $date->getTimestamp() .'-'. uniqid();




// 初始上传类
include 'Zend/File/Transfer/Adapter/Http.php';
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('IsImage', true);


echo 'start<br />';


// 上传处理
if ($upload->isUploaded()) {
	// 取得referMethod，判断是哪个页面来的编辑
	$referMethod = $_POST['referMethod'];

	echo 'uploaded<br />';

	// 取得后缀
	$ext = substr(strrchr($upload->getFileName(), '.'), 1);

	// 原始图片重命名
	$upload->addFilter('Rename', $imageName .'.'. $ext);

	// 根据referMethod作不同处理
	switch ($referMethod) {
		case 'article':

			echo 'inarticle<br />';

			$media = $config->media->toArray();
			$media = $media['image']['article'];
			// 如果文件夹不存在，则创建文件夹
			$imagePath = APPLICATION_PATH .'/../html'. $media['path'] .'/'. $subPath;
			if (!file_exists($imagePath)) {
				mkdir($imagePath);
			}
			$upload->setDestination($imagePath);
			// 接收
			if ($upload->receive()) {
				// 获取文件信息
				$fileInfo = $upload->getFileInfo();
				echo '<pre>';
				print_r($fileInfo);
				// 进行图像缩略
				include 'PhpThumb/ThumbLib.inc.php';
				$thumb = PhpThumbFactory::create($fileInfo['imgFile']['tmp_name']);
				$thumb->resize($media['thumbWidth']);
				$thumb->save($fileInfo['imgFile']['destination'] .'/'. $imageName .'.'. $ext);
			}
			break;
	}
} else {
	print_r($upload->getErrors());
}








    echo '<html>';
    echo '<head>';
    echo '<title>Insert Image</title>';
    echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
    echo '</head>';
    echo '<body>';
    //echo '<script type="text/javascript">parent.KE.plugin["image"].insert("' . $_POST['id'] . '", "' . $file_url . '","' . $_POST['imgTitle'] . '","' . $_POST['imgWidth'] . '","' . $_POST['imgHeight'] . '","' . $_POST['imgBorder'] . '");</script>';
	//echo '<script type="text/javascript">alert("'. $fileInfo .'");</script>';
	echo '<pre>';
	echo 'uuuu';
	print_r($fileInfo);
    echo '</body>';
    echo '</html>';


/*
//文件保存目录路径
$save_path = './../attached/';
//文件保存目录URL
$save_url = './../attached/';
//定义允许上传的文件扩展名
$ext_arr = array('gif', 'jpg', 'jpeg', 'png', 'bmp');
//最大文件大小
$max_size = 1000000;
//更改目录权限
@mkdir($save_path, 0777);

//有上传文件时
if (empty($_FILES) === false) {
    //原文件名
    $file_name = $_FILES['imgFile']['name'];
    //服务器上临时文件名
    $tmp_name = $_FILES['imgFile']['tmp_name'];
    //文件大小
    $file_size = $_FILES['imgFile']['size'];
    //检查文件名
    if (!$file_name) {
        alert("请选择文件。");
    }
    //检查目录
    if (@is_dir($save_path) === false) {
        alert("上传目录不存在。");
    }
    //检查目录写权限
    if (@is_writable($save_path) === false) {
        alert("上传目录没有写权限。");
    }
    //检查是否已上传
    if (@is_uploaded_file($tmp_name) === false) {
        alert("临时文件可能不是上传文件。");
    }
    //检查文件大小
    if ($file_size > $max_size) {
        alert("上传文件大小超过限制。");
    }
    //获得文件扩展名
    $temp_arr = explode(".", $file_name);
    $file_ext = array_pop($temp_arr);
    $file_ext = trim($file_ext);
    $file_ext = strtolower($file_ext);
    //检查扩展名
    if (in_array($file_ext, $ext_arr) === false) {
        alert("上传文件扩展名是不允许的扩展名。");
    }
    //新文件名
    $new_file_name = date("YmdHms") . '_' . rand(10000, 99999) . '.' . $file_ext;
    //移动文件
    $file_path = $save_path . $new_file_name;
    if (move_uploaded_file($tmp_name, $file_path) === false) {
        alert("上传文件失败。");
    }
    $file_url = $save_url . $new_file_name;
    //插入图片，关闭层
    echo '<html>';
    echo '<head>';
    echo '<title>Insert Image</title>';
    echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
    echo '</head>';
    echo '<body>';
    echo '<script type="text/javascript">parent.KE.plugin["image"].insert("' . $_POST['id'] . '", "' . $file_url . '","' . $_POST['imgTitle'] . '","' . $_POST['imgWidth'] . '","' . $_POST['imgHeight'] . '","' . $_POST['imgBorder'] . '");</script>';
    echo '</body>';
    echo '</html>';
}

//提示，关闭层
function alert($msg)
{
    echo '<html>';
    echo '<head>';
    echo '<title>error</title>';
    echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
    echo '</head>';
    echo '<body>';
    echo '<script type="text/javascript">alert("'.$msg.'");history.back();</script>';
    echo '</body>';
    echo '</html>';
    exit;
}
*/
?>